import { CHANGE_CURRENT, CHANGE_REGION_LIST, REGION_CHANGE_CURRENT } from './regionActiveTypes';

let defaultState = {
    // currentLocation:'',
    currentLocation: {
        id: 1,
        name: '上海市',
        pinyin: 'shanghai',
        latitude: 31.23037,
        longitude: 121.473701
      },//当前前所在位置
    regionList: [],
}
export default (state = defaultState, action) => {
    if (action.type === CHANGE_CURRENT) {
        let initState = JSON.parse(JSON.stringify(state));
        initState.currentLocation = action.value.value;
        return initState;
    }
    if (action.type === REGION_CHANGE_CURRENT) {
        let initState = JSON.parse(JSON.stringify(state));
        if (action.value.value.city_id) {
            state.regionList.cityList.forEach((item) => {
                item.cities.forEach((item) => {
                    if (item.id === action.value.value.city_id) {
                        initState.currentLocation = item;
                    }
                })
            })
        }
        return initState;
    }
    if (action.type === CHANGE_REGION_LIST) {
        // console.log(1223456);
        let initState = JSON.parse(JSON.stringify(state));
        initState.regionList = action.value.value;
        return initState;
    }
    return state;
}